/*
 * RightWidget.cpp
 *
 *  Created on: 2009-02-12
 *      Author: ck
 */

#include "RightWidget.h"

RightWidget::RightWidget(QWidget *parent) : QWidget(parent) {
	players = new QListWidget(this);
	spectators = new QListWidget(this);
	QVBoxLayout * vlay = new QVBoxLayout(this);
	QLabel * l1 = new QLabel("Players:");
	QLabel * l2 = new QLabel("Spectators:");
	setFixedWidth(150);
	players->setFixedHeight(100);
	vlay->addWidget(l1);
	vlay->addWidget(players);
	vlay->addWidget(l2);
	vlay->addWidget(spectators);
	spectators->setSortingEnabled(false);
	setLayout(vlay);
}

void RightWidget::updateLists(QStringList nicks) {
	players->clear();
	spectators->clear();
	spectatorsNicks.clear();
	playersNicks.clear();
	foreach(QString mnick, nicks) {
		QString mark = mnick.left(1);
		QString nick = mnick.mid(1);
		if (mark=="@") {
			addPlayerNick(nick);
		}
		else if (mark == "+") {
			addSpectatorNick(nick);
		}
	}
}

void RightWidget::addSpectatorNick(QString nick) {
	spectators->addItem(nick);
	spectatorsNicks.push_back(nick);
}

void RightWidget::addPlayerNick(QString nick) {
	players->addItem(nick);
	playersNicks.push_back(nick);
}

void RightWidget::removeSpectatorNick(QString nick) {
	int pos = spectatorsNicks.indexOf(nick);
	if (pos>=0) {
		delete spectators->takeItem(pos);
		spectatorsNicks.removeAt(pos);
	}

}

void RightWidget::removePlayerNick(QString nick) {
	int pos = playersNicks.indexOf(nick);
	if (pos>=0) {
		delete players->takeItem(pos);
		playersNicks.removeAt(pos);
	}
}

void RightWidget::clearNicks() {
	players->clear();
	spectators->clear();
	spectatorsNicks.clear();
	playersNicks.clear();
}

void RightWidget::boldPlayerNick(QString nick, bool bold) {
	int pos = playersNicks.indexOf(nick);
	if (pos>=0) {
		QFont font;
		font.setBold(bold);
		players->item(pos)->setFont(font);
	}
}

RightWidget::~RightWidget() {
	// TODO Auto-generated destructor stub
}
